package user_partner_reward

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPartnerRewardsUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新
func NewUserPartnerRewardsUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPartnerRewardsUpdateLogic {
	return &UserPartnerRewardsUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPartnerRewardsUpdateLogic) UserPartnerRewardsUpdate(req *types.UserPartnerUpdateRequest) (resp *types.UserPartnerUpdateResponse, err error) {
	_, err = l.svcCtx.AssetsRpc.User.UserPartnerRewardsUpdate(l.ctx, &rpc.UserPartnerUpdateRequest{
		Id:             req.Id,
		UserId:         req.UserId,
		InviteCode:     req.InviteCode,
		SubordinateId:  req.SubordinateId,
		RechargeAmount: req.RechargeAmount,
		RewardAmount:   req.RewardAmount,
		RechargeTime:   req.RechargeTime,
		RegisterTime:   req.RegisterTime,
	})
	if err != nil {
		return &types.UserPartnerUpdateResponse{
			IsUpdate: false,
		}, nil
	}
	return &types.UserPartnerUpdateResponse{
		IsUpdate: true,
	}, nil
}
